﻿using System.Collections.Generic;
using Game.Command;
using Game.Common;
using Game.Level;
using Game.Map;
using Game.Plugin;
using Game.Plugin.Parse;

namespace DebugPlugin
{
    public class ShowAllPlugin : AbstractPlugin
    {
        readonly CommandExecutor _CommandExecutor;
        readonly IGameMapView _GameMapView;
        readonly GameLevels _GameLevels;

        public ShowAllPlugin(
            CommandExecutor commandExecutor,
            IGameMapView gameMapView,
            GameLevels gameLevels,
            IGamePlugin parent) :
            base(parent, "showall")
        {
            _CommandExecutor = commandExecutor;
            _GameMapView = gameMapView;
            _GameLevels = gameLevels;
        }

        public override ICodeObject Parse(
            string token,
            ParserContext context)
        {
            IExpression e = new ShowAllExpression(
                _CommandExecutor,
                _GameMapView,
                _GameLevels);
            context.Stack.Push(e);
            return e;
        }
    }

    class ShowAllExpression : IExpression
    {
        readonly CommandExecutor _CommandExecutor;
        readonly IGameMapView _GameMapView;
        readonly GameLevels _GameLevels;

        public ShowAllExpression(
            CommandExecutor commandExecutor,
            IGameMapView gameMapView,
            GameLevels gameLevels)
        {
            _CommandExecutor = commandExecutor;
            _GameMapView = gameMapView;
            _GameLevels = gameLevels;
        }

        public object Interpret(Dictionary<string, ICodeObject> variables)
        {
            _CommandExecutor.Execute(
                _GameMapView, 
                _GameLevels, 
                GameTurn.Create(), new ShowAllCommand());
            return "success";
        }
    }
}
